package cn.bx.bid.entity;

public class Jw {
    public double lat, lng;

    public Jw() {
    }

    public Jw(double lat, double lng) {
        super();
        this.lat = lat;
        this.lng = lng;
    }

    public double dis(Jw w) {
        return getDistance(this.lat, this.lng, w.lat, w.lng);
    }

    @Override
    public String toString() {
        return "Jw [lat=" + lat + ", lng=" + lng + "]";
    }

    public static double getDistance(double Lat_A, double Lng_A, double Lat_B, double Lng_B) {
        double ra = 6378.140;
        double rb = 6356.755;
        double flatten = (ra - rb) / ra;
        double rad_lat_A = Math.toRadians(Lat_A);
        double rad_lng_A = Math.toRadians(Lng_A);
        double rad_lat_B = Math.toRadians(Lat_B);
        double rad_lng_B = Math.toRadians(Lng_B);
        double pA = Math.atan(rb / ra * Math.tan(rad_lat_A));
        double pB = Math.atan(rb / ra * Math.tan(rad_lat_B));
        double xx = Math
                .acos(Math.sin(pA) * Math.sin(pB) + Math.cos(pA) * Math.cos(pB) * Math.cos(rad_lng_A - rad_lng_B));
        double c1 = (Math.sin((xx) - xx) * (Math.sin(pA) + Math.sin(pB)) * 2 / Math.cos(xx / 2) * 2);
        double c2 = (Math.sin(xx) + xx) * (Math.sin(pA) - Math.sin(pB)) * 2 / Math.sin(xx / 2) * 2;
        double dr = flatten / 8 * (c1 - c2);
        double distance = ra * (xx + dr);
        // DecimalFormat format = new DecimalFormat("###.000");
        // distance = Double.parseDouble(format.format(distance));
        return Math.abs(distance);
    }
}
